﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using DataProcessor.Core;
using DataProcessor.FashionData;
using DataProcessor.DeeplinkData;
using System.Text.RegularExpressions;

namespace DataProcessor
{
    class Program
    {

        static void Main(string[] args)
        {
            ExecuteFashionProcessor();
            //ExecuteDeeplinkProcessor();
            //ExecuteMsraProcessor();
            //ExecuteHitProcessor();

            return;
        }

        static void ExecuteFashionProcessor(int num = 10)
        {
            FashionDataProcessor fdp = new FashionDataProcessor();

            switch (num)
            {
                case (1):
                    fdp.CreateHitInputFiles(
                        "FashionData/AttributionImages.csv", 
                        "FashionData/CategoryDefinitions.txt", 
                        "FashionData/HitInput.csv");
                    break;
                case(2):
                    fdp.ApplyRejection(
                        "FashionData/Results/Batch3.Reject.csv",
                        "FashionData/Results/Batch3.Original.csv",
                        "FashionData/Results/Batch3.Original.Approved.csv");
                    break;
                case (3):
                    fdp.GetAnswersPerImage(
                        "FashionData/Results/Experts All/AllBatches.Original.bsv",
                        "FashionData/Results/Experts All/Annotation_PerImage_Trusted.csv");
                    break;
                case (4):
                    fdp.GetAnswersStatisticsPerImage(
                        "FashionData/Results/Experts All/AllBatches.Original.bsv",
                        "FashionData/Results/Experts All/AllBatches.Original.PerImage.Statistics.csv");
                    break;
                case (5):
                    fdp.GetSameNonExpertAnnotationsForExpertAnnotations(
                        "FashionData/Results/AllBatches.Original.PerImage.Statistics_without pictures with 2 judgments.csv",
                        "FashionData/Results/Experts All/AllBatches.PerImage.Statistics.without 2rated pics.csv",
                        "FashionData/Results/Experts All/Non-expert.PerImage.Statistics.without 2rated pics.csv");
                    break;
                case (6):
                    fdp.CalculateMajorityVoting(
                        "FashionData/Results/Experts All/AllBatches.PerImage.Statistics.without 2rated pics.csv",
                        "FashionData/Results/Experts All/Expert.Voting.csv");
                    break;
                case (7):
                    fdp.MergeMajorityVotings(
                        "FashionData/Results/Experts All/Expert.Voting.csv",
                        "FashionData/Results/Experts All/Non-expert.Voting.csv",
                        "FashionData/Results/Experts All/All.Voting.csv");
                    break;
                case(8):
                    fdp.GetDataStatistic(
                        "FashionData/Results/Experts/Experts.Original.bsv",
                        "FashionData/Results/Experts/Experts.Statistics.tsv");
                    break;
                case(9):
                    fdp.MergePhotoInfo(
                        "FashionData/Results/Experts/selected_fashion_urls.bsv",
                        "FashionData/Results/Experts All/Annotation_PerImage_Trusted.csv",
                        "FashionData/Results/Annotation_PerImage_Trusted.Merged.csv");
                    break;
                case(10):
                    fdp.ReplaceWorkerIdWithIndex(
                        "FashionData/Results/Experts All/AllBatches.Original.csv",
                        "FashionData/Results/Experts All/Experts.AllBatches.WithoutWorkerId.csv");
                    break;
                default:
                    break;
            }
        }

        static void ExecuteDeeplinkProcessor(int num = 21)
        {
            DeeplinkDataProcessor ddp = new DeeplinkDataProcessor();

            switch (num)
            { 
                case(1):
                    Console.WriteLine("Num. of duplicte records: {0}", ddp.GetNumVideoIdDuplicates(
                        "DeeplinkData/Vids1.csv",
                        "DeeplinkData/Vids2.csv"));
                    Console.Read();
                    break;
                case(2):
                    ddp.GetDeeplinksPerShot(
                        "DeeplinkData/Deeplinks.csv",
                        "DeeplinkData/YoutubeIndeces.csv",
                        @"D:\Data\University\Timecode Aware Project\Data\MSRA",
                        "DeeplinkData/Keyframes.csv");
                    break;
                case(3):
                    ddp.GetLibSvmFeatures(
                        "DeeplinkData/YoutubeIndeces.csv",
                        "DeeplinkData/Keyframes.csv",
                        @"D:\Data\University\Timecode Aware Project\Data\MSRA",
                        "DeeplinkData/Correlogram144.csv",
                        "Correlogram144",
                        0, 200);
                    break;
                case(4):
                    ddp.GetShotNum(
                        "DeeplinkData/YoutubeIndeces_En.csv",
                        @"D:\Data\University\Timecode Aware Project\Data\MSRA",
                        "DeeplinkData/ShotNumbers.csv");
                    break;
                case(5):
                    ddp.JoinFeatureFiles(
                        "DeeplinkData/RawFeatures.csv",
                        "DeeplinkData/ShotNumbers.csv",
                        "DeeplinkData/Dataset.csv");
                    break;
                case(6):
                    ddp.SplitDataset(
                        "DeeplinkData/Dataset.csv",
                        "DeeplinkData/Train.csv",
                        "DeeplinkData/Test.csv",
                        0.8);
                    break;
                case(7):
                    ddp.GetPerVideoVotes(
                        "DeeplinkData/AmtResult.csv",
                        "DeeplinkData/PerVideoVotes.csv");
                    break;
                case(8):
                    ddp.GetDataSetFeatures(
                        "DeeplinkData/Expert33/Amt.Original.csv",
                        "DeeplinkData/Expert33/CommentsData.csv",
                        new string[] { "Input.COMMENT", "Answer.tcTypes" });
                    break;
                case(9):
                    ddp.GetVideoShotsAndKeyframes(
                        "DeeplinkData/YoutubeIndeces.csv",
                        @"D:\Data\Datasets\MSRA",
                        "DeeplinkData/PilotHit2VideoShots.csv",
                        "DeeplinkData/PilotHit2VideoIds.csv");
                    break;
                case(10):
                    ddp.CreateFFMpegCommandForAllVideos(
                       @"L:\mm\D-MIRLab\cubrik\icmr13_msra\bayes",
                        "DeeplinkData/FFMpegCommands.bat");
                    break;
                case(11):
                    ddp.GenerateMatlabCodeToDrawAudioDeeplinks(
                        "DeeplinkData/Expert33/DeeplinksWithTypes.csv",
                        @"Q:\cubrik\icmr13_msra\PilotHit2 Videos",
                        "DeeplinkData/PilotHit2VideoShots.csv",
                        "DeeplinkData/Expert33/Expert33AudioDeeplinkVisualizer.m");
                    break;
                case(12):
                    ddp.SelectRandomVideoIds(
                        "DeeplinkData/Deeplinks.csv",
                        "DeeplinkData/VideoIds.csv",
                        101);
                    break;
                case(13):
                    ddp.FindVideoPathsOnServer(
                        "DeeplinkData/PilotHit2VideoIds.csv",
                        @"Q:\cubrik\icmr13_msra",
                        "DeeplinkData/PilotHit2VideoPaths.csv");
                    break;
                case (14):
                    ddp.CreateFFMpegCommandForAllVideos2(
                        "DeeplinkData/PilotHit2VideoPaths.csv",
                        "DeeplinkData/FFMpegCommands.bat",
                        @"Q:\cubrik\icmr13_msra\PilotHit2 Videos");
                    break;
                case(15):
                    ddp.GetHitVideoIds(
                        "DeeplinkData/HitDeeplinks.csv",
                        "DeeplinkData/HitVideoIds.csv");
                    break;
                case(16):
                    ddp.GetPathVideoIds(
                        @"L:\mm\D-MIRLab\cubrik\icmr13_msra\bayes",
                        "DeeplinkData/SampleVideoIdsForGraph.csv");
                    break;
                case (17):
                    ddp.GenerateDeeplinksWithTypes(
                        "DeeplinkData/Expert33/Amt.Original.csv",
                        "DeeplinkData/Expert33/DeeplinksWithTypes.csv");
                    break;
                case(18):
                    ddp.GenerateCommentDatasets(
                        "DeeplinkData/Expert33/Amt.Original.csv",
                        "DeeplinkData/Expert33/CommentsTrain.csv",
                        "DeeplinkData/Expert33/CommentsTest.csv");
                    break;
                case (19):
                    ddp.GenerateDeeplinkTypeForVideos(
                        "DeeplinkData/Expert33/CommentsData.csv",
                        "DeeplinkData/Expert33/VideoDeeplinks.csv");
                    break;
                case(20):
                    var res = ddp.ExtractTimeCodes("# T: 1m30s, a0:33b, 1:40 (past video end), 0:07., 0:32a  F: 0:00:12, 00:00:23, 0:007, 0h01m10s, 000:10");
                    res.ForEach(Console.WriteLine);
                    break;
                case(21):
                    ddp.GetAudioFilesPath(
                        @"Q:\cubrik\icmr13_msra\PilotHit2 Videos",
                        "DeeplinkData/Expert33/AudioPaths.csv");
                    break;
                default:
                    break;
            }
        }

        static void ExecuteMsraProcessor(int num = 5)
        {
            MsraDataProcessor mdp = new MsraDataProcessor("DeeplinkData/MSRA/MSRAVideos.csv", "DeeplinkData/MSRA/ids_downloaded_eng.txt");
            
            switch (num)
            { 
                case(1):
                    mdp.PrintBasicResults();
                   break;
                case (2):
                   mdp.FilterDataset("DeeplinkData/MSRA/MSRAVideos.csv", "DeeplinkData/MSRA/ids_train.txt", "DeeplinkData/MSRA/MSRAVideosTrain.csv");
                   break;
                case(3):
                   mdp.WriteDataset(@"Q:\cubrik\icmr13_msra", "DeeplinkData/MSRA/100DeeplinkVideos.csv", true);
                   break;
                case (4):
                   mdp.CreateFFMpegCommand("DeeplinkData/MSRA/100DeeplinkVideos.csv", "DeeplinkData/MSRA/100DeeplinkFFMpeg.bat", @"Q:\cubrik\icmr13_msra\100 Deeplink Audios");
                   break;
                case (5):
                   mdp.ListAudioFiles(@"Q:\cubrik\icmr13_msra\100 NonDeeplink Audios", "DeeplinkData/MSRA/100NonDeeplinkAudios.csv");
                   break;
                default:
                    break;
            }
        }

        static void ExecuteHitProcessor(int num = 7)
        {
            HitProcessor hp = new HitProcessor("DeeplinkData/PublicHit/Batch1.csv")
                .AddInputFile("DeeplinkData/PublicHit/Batch2.csv")
                .AddInputFile("DeeplinkData/PublicHit/Batch3.csv")
                .AddInputFile("DeeplinkData/PublicHit/Batch4.csv")
                .AddInputFile("DeeplinkData/PublicHit/Batch5.csv");

            switch (num)
            {
                case (1):
                    hp.CalculateAggreements("DeeplinkData/PublicPilot2/votes.csv");
                    break;
                case (2):
                    hp.FilterMismatchsInAnswers("DeeplinkData/PublicHit/AllBatchesWorkers.csv")
                        .WorkersAnnotations("DeeplinkData/PublicHit/AllSpiritsFiltered.tsv");
                    break;
                case (3):
                    hp.SpiritCategories("DeeplinkData/PublicPilot2/SpiritCategories.tsv");
                    break;
                case (4):
                    hp.FilterUnseriousWorkers().CalculateAggreements("DeeplinkData/PublicPilot2/VotesFiltered.csv");
                    break;
                case (5):
                    hp.FilterMismatchsInAnswers("DeeplinkData/PublicHit/AllBatchesWorkers.csv")
                        .UseDatabaseComments("DeeplinkData/PublicHit/AllMsraComments.csv")
                        .CalculateAggreements("DeeplinkData/PublicHit/AllBatchesVotesFiltered.csv");
                    break;
                case(6):
                    hp.PrintStatistics();
                    break;
                case(7):
                    hp.PrintCommentPerVideoGraph("DeeplinkData/MSRA/MSRAVideos.csv");
                    break;
                default:
                    break;
            }
        }
    }

}
